// Copyright (C) joyinter
// All rights reserved.
// 
// Author : Jiang Li
// Date   : 2004-11-19

#ifndef __BASE_TIMER_H_COMMON_SVR_BASE__
#define __BASE_TIMER_H_COMMON_SVR_BASE__

#pragma once

#include "base_thread.h"

namespace JoyServer
{

//##ModelId=44CEFAD10050
class CJoyTimerObject
{
protected:
    friend class CJoyTimer;

	//##ModelId=44CEFAD10052
    CJoyTimer*  m_timer;
	//##ModelId=44CEFAD1005D
    DWORD       m_elapse;
	//##ModelId=44CEFAD1005E
    DWORD       m_lastActive;

	//##ModelId=44CEFAD1005F
    virtual void OnExecute();

public:
	//##ModelId=44CEFAD10061
    CJoyTimerObject();
	//##ModelId=44CEFAD10062
    virtual ~CJoyTimerObject();

	//##ModelId=44CEFAD10064
    bool Create(CJoyTimer* pTimer, DWORD dwElapse);
	//##ModelId=44CEFAD1006F
    void Destroy();

	//##ModelId=44CEFAD10070
    void Execute();

	//##ModelId=44CEFAD10071
    void Update();
};

//##ModelId=44CEFAD1007D
class CJoyTimer : public CJoyThread
{
protected:
    friend class CJoyTimerObject;

	//##ModelId=44CEFAD1007F
    HANDLE  m_hEvent;
	//##ModelId=44CEFAD10080
    DWORD   m_tick;

	//##ModelId=44CEFAD10082
    CJoyCriticalSection     m_lock;
	//##ModelId=44CEFAD1008D
    CList<CJoyTimerObject*> m_objects;

	//##ModelId=44CEFAD10091
    void TrackObjects();

	//##ModelId=44CEFAD10092
    virtual DWORD ThreadProc();
public:
	//##ModelId=44CEFAD1009D
    CJoyTimer();
	//##ModelId=44CEFAD1009E
    virtual ~CJoyTimer();

	//##ModelId=44CEFAD100A0
    bool Create(DWORD dwTick = 100);
	//##ModelId=44CEFAD100A2
    void Destroy();

	//##ModelId=44CEFAD100A3
    void AddObject(CJoyTimerObject* pObj);
	//##ModelId=44CEFAD100AB
    void RemoveObject(CJoyTimerObject* pObj);
};


} // namespace JoyServer

#endif  // __BASE_TIMER_H_COMMON_SVR_BASE__
